﻿using System;
using System.Collections.Generic;
using System.Text;
using Eb;

public class D
{
    byte[] buf = new byte[102400];
}

public class C
{
    public C()
    {
        EbLog.Note("C");
    }

    ~C()
    {
        EbLog.Note("~C");
    }
}

public class A : IDisposable
{
    //---------------------------------------------------------------------
    public bool Disposed { internal set; get; }

    //---------------------------------------------------------------------
    ~A()
    {
        EbLog.Note("~A");

        Dispose(false);
    }

    //---------------------------------------------------------------------
    public void Dispose()
    {
        Dispose(true);

        GC.SuppressFinalize(this);
    }

    //---------------------------------------------------------------------
    protected void Dispose(bool disposing)
    {
        if (!Disposed)
        {
            if (disposing)
            {
            }

            EbLog.Note("A.Dispose() disposing=" + disposing);

            Disposed = true;
        }
    }

    public void show()
    {
        EbLog.Note("A.show() AAAAAAAAAAAAA");
    }
}

public class B : IDisposable
{
    //---------------------------------------------------------------------
    A mA = new A();
    C mC = new C();
    string mStr = "adasdfasdf";
    
    //---------------------------------------------------------------------
    public bool Disposed { internal set; get; }

    //---------------------------------------------------------------------
    ~B()
    {
        EbLog.Note("~B");

        Dispose(false);
    }

    //---------------------------------------------------------------------
    public void Dispose()
    {
        Dispose(true);

        GC.SuppressFinalize(this);
    }

    //---------------------------------------------------------------------
    protected void Dispose(bool disposing)
    {
        if (!Disposed)
        {
            if (disposing)
            {
                mA.Dispose();
            }

            EbLog.Note("B.Dispose() disposing=" + disposing);

            Disposed = true;
        }
    }

    //---------------------------------------------------------------------
    public void show()
    {
        EbLog.Note("B.show() ");
        mA.show();
    }
}

public delegate void OnEntityCreate();
class TestDummy : Test
{
    B mB1 = null;
    public OnEntityCreate OnEntityCreate { get; set; }

    //-------------------------------------------------------------------------
    public override void init()
    {
        EbLog.Note("TestDummy.init()");

        using (mB1 = new B())
        {
            OnEntityCreate += mB1.show;
        }
        mB1 = null;

        //B B2 = new B();
    }

    //-------------------------------------------------------------------------
    public override void release()
    {
        EbLog.Note("TestDummy.release()");
    }

    //-------------------------------------------------------------------------
    public override void update()
    {
        D d = new D();

        if (OnEntityCreate != null)
        {
            OnEntityCreate();
            OnEntityCreate = null;
        }

        GC.Collect();

        //b.show();

        //if (b != null)
        //{
        //    B a = b;
        //}

        //if (b == null)
        //{
        //    EbLog.Note("b==null");
        //}
        //else if (b.Disposed)
        //{
        //    EbLog.Note("b!=null  && b.Disposed=true");
        //}
        //else
        //{
        //    EbLog.Note("b!=null  && b.Disposed=false");
        //}
    }
}
